﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using com.Bliss.Services;
using System.Web.Security;

public partial class Login : NonSecuredBaseView
{
    DataBaseClass dbClass = new DataBaseClass();
    public DataTable dt;

    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void OnAuthenticate(object sender, AuthenticateEventArgs e)
    {
        bool Authenticated = false;
        Authenticated = UserAuthenticate(ctlLogin.UserName, ctlLogin.Password);
        e.Authenticated = Authenticated;
        if (Authenticated == true)
        {
            FormsAuthentication.RedirectFromLoginPage(UserName, ctlLogin.RememberMeSet);
        }
    }

    private bool UserAuthenticate(string userName, string password)
    {
        bool boolReturnValue = false;
        IUserService service = new UserService();
        var userService = service.ValidateUserLogin(userName, password);
        com.Bliss.User user = userService.Data;
        if (user != null)
        {
            boolReturnValue= true;
            UserID = user.ID;
            UserName = user.Email;
            CompanyID = user.CompanyID;
            ImageName = user.ImageName;
        }
        else
        {
            UserID = null;
            UserName = string.Empty;
            CompanyID = null;
            ImageName = string.Empty;
            boolReturnValue = false;
        }
        return boolReturnValue;
    }
    protected void lnkRegister_Click(object sender, EventArgs e)
    {
        Response.Redirect("Register.aspx");
    }
}
